ok below is my SQL procedure on SSMS to get Datafrom SAP 
Currently is flush and fill - 
if we want incremental load from date entered how to do that - what I know @Load_Type we have to change to 1 but what other logic we need to built ?

Creation Date is Date and Creation Time is Time filelds which I want to use for Inremental load means new data from this two field is insert instead of truncate and fill- below Query returnd me json format of data where as example Creation date I am getting 1718755200000 and creation time I am getting PT06H53M59S in ssms.

USE [_Experimental]
GO
/****** Object:  StoredProcedure [dbo].[sp_ZPTP_C_Material_Document_Header_2_Refresh]    Script Date: 9/12/2024 4:41:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create or ALTER PROCEDURE [dbo].[sp_ZPTP_C_Material_Document_Header_2_Refresh]
AS 

SET NOCOUNT ON;

 -- Job is executing, set TEXTSIZE to maximum
			   SET TEXTSIZE 2147483647;

-- always the same for multi-step
	DECLARE 
		  @Database_Name varchar(255)=DB_NAME(), @Procedure_Name varchar(255)=OBJECT_NAME(@@PROCID), @Start_Time_Stamp DateTime=getdate()
		, @Start_Step DateTime=getdate(), @Step varchar(255)='', @Action varchar(255)='', @Table_Name nvarchar(300), @SQL nvarchar(100)
		, @Result varchar(4), @Record_Count int=0, @Source_Record_Count int=0
		, @Error_Number int, @Error_State int, @Error_Severity int, @Error_Line int, @Error_Message varchar(255),@Notes nvarchar(256);
	exec Administration.dbo.sp_Record_Event @Database_Name=@Database_Name,  @Procedure_Name=@Procedure_Name, @Start_Time_Stamp=@Start_Time_Stamp, @Step='Start',@Notes='';	

	/******** end of always the same, flex below to match context *******************************************************/	

   -- VARIABLE DECLARATION RELATED TO THE OBJECT

--Static
    DECLARE @Load_Type int,@ErrorDescription NVARCHAR(1000),@Url_Record_Response int;
    DECLARE @xml AS TABLE (xml_table NVARCHAR(MAX));DECLARE @Object INT,@ObjResponseText INT, @Status INT, @ResponseBody VARBINARY(MAX), @ResponseText NVARCHAR(MAX), @AuthHeader NVARCHAR(300);
	DECLARE @json_Table TABLE (json_table NVARCHAR(MAX));
	DECLARE @json_Data NVARCHAR(MAX);
--Control
    DECLARE @SAPAccessToken NVARCHAR(255) = Administration.dbo.GenerateSAPAccessToken('PROD'); -- FUNCTION call Required to get Access Token
	DECLARE @ResponseType nvarchar(6) = 'json'; --can swap between json and xml, required in header passing
	DECLARE @Url nvarchar(300) = 'https://gentexprod.apim.cre.scp.sapns2.us:443/ZPTP_C_MaterialDocumentHeader_2/ZPTP_C_MatDocHeader2'; --Must Declare URL API To Function
	DECLARE @Url_Records nvarchar(300) = @Url+'/$count';
	DECLARE @ThirdSlashIndex INT = CHARINDEX('/', @Url, CHARINDEX('/', @Url, CHARINDEX('/', @Url) + 1) + 1);
	DECLARE @FourthSlashIndex INT = CHARINDEX('/', @Url, @ThirdSlashIndex + 1);
	SET @Table_Name = SUBSTRING(@Url, @ThirdSlashIndex + 1, @FourthSlashIndex - @ThirdSlashIndex - 1)
	SET @Table_Name = _Functions.dbo.AddUnderscores(SUBSTRING(@Table_Name, CHARINDEX('_', @Table_Name, CHARINDEX('_', @Table_Name) + 1) + 1, LEN(@Table_Name)));
	
	--EXEC _Native_SAP.dbo.sp_Update_Dynamic_SAP_API_List @Url = @Url, @Area = 'PROD';
	DECLARE @Batch_RequestSize int = 3000
	DECLARE @Number_Of_Columns int = (SELECT distinct count(*)FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @Table_Name group BY  TABLE_NAME);
	DECLARE @ReductionPercentage DECIMAL(5,2) = 
    CASE
        WHEN @Number_Of_Columns BETWEEN 30 AND 59 THEN .30 -- Reduce batch size by 30% depending on table having alot of records,
		WHEN @Number_Of_Columns BETWEEN 60 AND 89  THEN .60  -- Reduce batch size by 60% depending on table having alot of records,
		WHEN @Number_Of_Columns >= 90 THEN .90 -- Reduce batch size by 90% depending on table having alot of records,
        ELSE 0
    END;

-- Calculate the Batch_RequestSize based on the reduction percentage
	SET @Batch_RequestSize = @Batch_RequestSize - CAST(@ReductionPercentage * @Batch_RequestSize AS INT);	--dynmatically alters batch size based on number of columns in table
	Set @Load_Type = 1;			--0 is Flush and Fill, 1 is incremental with a date range designator, decides what URL parameters to run,
		if @Load_Type = 0
			set @Url = @Url+'?$top='+cast(@Batch_RequestSize as NVARCHAR) 
		else 
			set @Url = @Url+'?$top='+@Batch_RequestSize+'' -- Date Range or some Type of Date required for incremental, format like ge createdate 01/01/2024 le 06/02/2024
		
	DECLARE @BaseUrl nvarchar(300) = @url;
		if @Load_Type = 0	
		DECLARE @DynamicSQL NVARCHAR(MAX)= 'TRUNCATE TABLE _Experimental.dbo.' + QUOTENAME(@Table_Name);		EXEC sp_executesql @DynamicSQL; --depending on Load Type Variable depends if the table truncates or not
		

-- Step 1: Get total number of Records in Table from Request, used to Generated the Number Loops to load in Step 2
	Begin TRY
		Set	@Step='1) Get Record Count of Table'; Set @Start_Step=getdate(); Set @Action=case when @Load_Type = 0 then 'Flush & Fill' else 'Incremental' end; Set @Table_Name = @Table_Name; 
		
	BEGIN 
			EXEC @ObjResponseText = sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;    --IF @ObjResponseText <> 0 RAISEERROR('unable to open http connection.', 10, 1);
			EXEC @ObjResponseText = sp_OAMethod @Object, 'open', NULL, 'GET', @Url_Records, 'false';--    IF @ObjResponseText <> 0 RAISEERROR('issue testing connection', 10, 1);
			EXEC Administration.dbo.sp_SAP_API_Set_Request_Headers @Object, @SAPAccessToken,@ResponseType;
		
			EXEC @ObjResponseText = sp_OAMethod @Object, 'send';
			EXEC @ObjResponseText = sp_OAGetProperty @Object, 'status', @Status OUT;
			EXEC @ObjResponseText = sp_OAGetProperty @Object, 'responseText', @Url_Record_Response OUT;
			IF @Status <> 200
			BEGIN
			SET @ErrorDescription = CASE
				WHEN @Status = 400 THEN 'Bad Request ' + COALESCE(@ResponseText, '')
				WHEN @Status = 401 THEN 'Unauthorized ' + COALESCE(@ResponseText, '')
				WHEN @Status = 403 THEN 'Forbidden ' + COALESCE(@ResponseText, '')
				WHEN @Status = 404 THEN 'Not Found ' + COALESCE(@ResponseText, '')
				WHEN @Status = 500 THEN 'Internal Server Error ' + COALESCE(@ResponseText, '')
				WHEN @Status = 502 THEN 'Bad Gateway ' + COALESCE(@ResponseText, '')
				-- Add more cases as needed
				ELSE 'Unknown Error'
			END;--error response if any
			END
		END -- Send headers and Error Handle

	 SET @Url_Record_Response = COALESCE(@Url_Record_Response, ''); 
		DECLARE @LoopCounter int = CEILING(CAST(@Url_Record_Response AS decimal) / @Batch_RequestSize);
	
	------end of unique instructions for this step --------------------------------
		set	@Record_Count=@Url_Record_Response; SET @Result='Pass';SET @Notes = 'Expected # of Loops to Load in Step 2: ' +  CAST(@LoopCounter AS varchar(10))

	END TRY
	BEGIN CATCH
		SET @Result='Fail'; SET @Record_Count=0; 
		SET @ERROR_NUMBER=ERROR_NUMBER(); SET @ERROR_STATE=ERROR_STATE(); SET @ERROR_SEVERITY=ERROR_SEVERITY(); SET @ERROR_LINE=ERROR_LINE(); SET @ERROR_MESSAGE=ERROR_MESSAGE();
	END CATCH; --get supporting information for loop
	exec Administration.dbo.sp_Record_Event 
		  @Result=@Result, @Database_Name=@Database_Name,  @Procedure_Name=@Procedure_Name, @Step=@Step, @Action=@Action, @Table_Name=@Table_Name
		, @Start_Time_Stamp=@Start_Step, @Record_Count=@Record_Count
		, @ERROR_NUMBER=@ERROR_NUMBER, @ERROR_STATE=@ERROR_STATE, @ERROR_SEVERITY=@ERROR_SEVERITY,@ERROR_LINE=@ERROR_LINE, @ERROR_MESSAGE=@ERROR_MESSAGE,@Notes=@Notes; --logs event

---- Step 2: Loop load batches of Data, # of Loops derived from Step 1
BEGIN TRY
		Set	@Step='2) Loop & Load'; Set @Start_Step=getdate(); Set @Action=case when @Load_Type = 0 then 'Flush & Fill' else 'Incremental' end; Set @Table_Name = @Table_Name; 
	Declare @i int = 1,@TotalRecordCount int = 0; -- loop variables
	while @i <= @LoopCounter
		begin	
			if @i > 1 
			SET @Url = @BaseUrl + '&$skip=' + cast( @Batch_RequestSize * (@i-1) as nvarchar(100));

			begin 
			EXEC @ObjResponseText = sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;    --IF @ObjResponseText <> 0 RAISEERROR('unable to open http connection.', 10, 1);
			EXEC @ObjResponseText = sp_OAMethod @Object, 'open', NULL, 'GET', @Url, 'false';--    IF @ObjResponseText <> 0 RAISEERROR('issue testing connection', 10, 1);
			EXEC Administration.dbo.sp_SAP_API_Set_Request_Headers @Object, @SAPAccessToken,@ResponseType;
		
			EXEC @ObjResponseText = sp_OAMethod @Object, 'send';
			EXEC @ObjResponseText = sp_OAGetProperty @Object, 'status', @Status OUT;
			EXEC @ObjResponseText = sp_OAGetProperty @Object, 'responseText', @Url_Record_Response OUT;
	
					IF @Status <> 200
					begin
						SET @ErrorDescription = 
						CASE
								WHEN @Status = 400 THEN 'Bad Request ' + COALESCE(@ResponseText, '')
								WHEN @Status = 401 THEN 'Unauthorized ' + COALESCE(@ResponseText, '')
								WHEN @Status = 403 THEN 'Forbidden ' + COALESCE(@ResponseText, '')
								WHEN @Status = 404 THEN 'Not Found ' + COALESCE(@ResponseText, '')
								WHEN @Status = 500 THEN 'Internal Server Error ' + COALESCE(@ResponseText, '')
								WHEN @Status = 502 THEN 'Bad Gateway ' + COALESCE(@ResponseText, 'Body Buffer Likely to big, make batch size smaller')
								-- Add more cases as needed
								ELSE 'Unknown Error'
						
						END;--error response if any
						THROW 51000, @ErrorDescription, 1;
					END
				
-- Insert the response text into a table
INSERT INTO @json_Table (json_table) EXEC sp_OAGetProperty @Object, 'responseText';
SET @json_Data = (SELECT json_table FROM @json_Table);

-----**********Paste results from [dbo].[sp_Generate_SAP_Table_Structure_JSON] below ***************
Insert Into _Experimental.dbo.Material_Document_Header_2 Select
getdate() Data_Time_Stamp,
Material_Document_Year,
Material_Document,
_Functions.dbo.StripNonNumerics(Document_Date),
_Functions.dbo.StripNonNumerics(Posting_Date),
Accounting_Document_Type,
Inventory_Transaction_Type,
Created_By_User,
_Functions.dbo.StripNonNumerics(Creation_Date),
Creation_Time,
_Functions.dbo.StripNonNumerics(Changed_On_Date),
Material_Document_Header_Text,
Delivery_Document,
Reference_Document,
Bill_Of_Lading
FROM OPENJSON(@json_Data, '$.d.results') WITH (
Data_Time_Stamp datetime '$.DataTimeStamp',
Material_Document_Year nvarchar (4) '$.MaterialDocumentYear',
Material_Document varchar (10) '$.MaterialDocument',
Document_Date nvarchar (256) '$.DocumentDate',
Posting_Date nvarchar (256) '$.PostingDate',
Accounting_Document_Type varchar (2) '$.AccountingDocumentType',
Inventory_Transaction_Type varchar (2) '$.InventoryTransactionType',
Created_By_User varchar (12) '$.CreatedByUser',
Creation_Date nvarchar (256) '$.CreationDate',
Creation_Time nvarchar (256) '$.CreationTime',
Changed_On_Date nvarchar (256) '$.ChangedOnDate',
Material_Document_Header_Text varchar (25) '$.MaterialDocumentHeaderText',
Delivery_Document varchar (10) '$.DeliveryDocument',
Reference_Document varchar (16) '$.ReferenceDocument',
Bill_Of_Lading varchar (16) '$.BillOfLading')
;		
			SET @TotalRecordCount= @TotalRecordCount+  @@ROWCOUNT;


				SET @i = @i + 1;
				DELETE FROM @json_Table;	--removes any existing xml strings in the variable to allow next batch to process without duplication
				
			END
	END
		------end of unique instructions for this step --------------------------------
		set	@Record_Count=@@ROWCOUNT; SET @Result='Pass';set	@Notes='Processed: ' +   CAST(@Notes AS varchar(10)) +'  of ' + CAST(@@ROWCOUNT AS varchar(10));
	EXEC Administration.dbo.sp_SAP_API_Close_HTTP_Object @Object; -- Close & Destroy the HTTP object
end TRY

	begin CATCH
		SET @Result='Fail'; SET @Record_Count=0; 
		SET @ERROR_NUMBER=ERROR_NUMBER(); SET @ERROR_STATE=ERROR_STATE(); SET @ERROR_SEVERITY=ERROR_SEVERITY(); SET @ERROR_LINE=ERROR_LINE(); SET @ERROR_MESSAGE=ERROR_MESSAGE();
		SET	@Notes='Processed: ' +   CAST(@Notes AS varchar(10)) +'  of ' + CAST(@LoopCounter AS varchar(10));
		EXEC Administration.dbo.sp_SAP_API_Close_HTTP_Object @Object; -- Close & Destroy the HTTP object
	END CATCH;
	exec Administration.dbo.sp_Record_Event 
		  @Result=@Result, @Database_Name=@Database_Name,  @Procedure_Name=@Procedure_Name, @Step=@Step, @Action=@Action, @Table_Name=@Table_Name
		, @Start_Time_Stamp=@Start_Step, @Record_Count=@Record_Count
		, @ERROR_NUMBER=@ERROR_NUMBER, @ERROR_STATE=@ERROR_STATE, @ERROR_SEVERITY=@ERROR_SEVERITY,@ERROR_LINE=@ERROR_LINE, @ERROR_MESSAGE=@ERROR_MESSAGE,@Notes=@Notes; --Logs Step 2 Event


	WAITFOR DELAY '00:00:01';		
	exec Administration.dbo.sp_Record_Event @Database_Name=@Database_Name,  @Procedure_Name=@Procedure_Name, @Start_Time_Stamp=@Start_Time_Stamp, @Step='End';	
										
-- ******* end of flex, below is always the same **********************************************************************

  -- EXEC  sp_ZPTP_C_Material_Document_Header_2_Refresh 		Select count (*) from Material_Document_Header_2