Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Pico
Partner - Creator
Partner - Creator

Peek in a loop not working

Hi, I have my config table like this

Pico_0-1690196037480.png

an with the following code 

LET vNumTab = NoOfRows('TabConfig');

For j=1 to $(vNumTab)

LET vSchemaTemp = peek('Schema', $(j)-1, 'TabConfig' );
LET vDatabaseObjectTemp = peek('DB_Obj', $(j)-1,' TabConfig' );
LET vTableNameTemp = peek('TableName', $(j)-1, 'TabConfig' );
LET vCampoDateTemp = peek('CampoDate', $(j)-1, 'TabConfig' );
Trace >>> $(j) di $(vNumTab): $(vSchemaTemp).$(vDatabaseObjectTemp) for $(vTableNameTemp);

[.. other things, the error is above..]

I get this :

Pico_4-1690196384998.png

 

As you can see, the first look goes smoothly, but the second, ONLY the DB Objet is null, while the others are correct. 

What's happening? What am I missing?

Thank you very much

have a great day

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

I could imagine that the table-name TabConfig is wrong. In this case peek() couldn't refer to the table - but it won't return an error else just referencing to the last loaded table. In your first iteration this is the config-table but not in the second iteration because the last load were your oracle-query.

Therefore take another look on the table-name if you fetched the right one and spelled it properly. You may it also including within your trace-logic, with something like:

let vTable = tablename(nooftables());
trace LastLoadedTable is: $(vTable);

View solution in original post

4 Replies
marcus_sommer

I think I would comment the load-part within the loop and look what the trace returned for all the other iterations. If anything is wrong it would be probably more often as just for one variable-value in the second run. If so it may give valuable hints to the real cause - maybe a not existing table TabConfig or this table has another content as expected.

Pico
Partner - Creator
Partner - Creator
Author

Nice idea, and it got me an interesting result: the loop is working correctly if  I comment the following code, but gives me again the error once un-commented it.
Hence the second part of the code is somehow related to the error.

These are the following parts of the code:

 

LET vSoubRoutineType = if(len(vCampoDateTemp)>0, 'His','Simple'); //this is fine

CALL Datawarehouse_$(vSoubRoutineType) (vServer, vSchemaTemp, vDatabaseObjectTemp, vTableNameTemp,vCampoDateTemp); //this seems to be fine, but once I coment it, the loops works 🙂

 

Tha call (in another Sections) are the following:

 

Sub Datawarehouse_Simple (vServer,vSchema,vDatabaseObject,vTableName,vCampoDate)

LIB CONNECT TO '$(vServer)';

$(vTableName): SQL SELECT * FROM $(vSchema).$(vDatabaseObject);

Store $(vTableName) into $(vStore_QVD_00)\$(vTableName).qvd (qvd);

DisConnect;

End Sub

//and the second Sub:

Sub Datawarehouse_His (vServer,vSchema,vDatabaseObject,vTableName,vCampoDate)

LIB CONNECT TO '$(vServer)';

$(vTableName): SQL SELECT * FROM $(vSchema).$(vDatabaseObject) where $(vCampoDate) = (select max($(vCampoDate)) from $(vSchema).$(vDatabaseObject));

Store $(vTableName) into $(vStore_QVD_00)\$(vTableName).qvd (qvd);

DisConnect;

End Sub.

 

Long story short: Datawarehouse_Simple is a Load * from,

Datawarehouse_His is a load * where date is max.

 

What could the error possibly be?

 

marcus_sommer

I could imagine that the table-name TabConfig is wrong. In this case peek() couldn't refer to the table - but it won't return an error else just referencing to the last loaded table. In your first iteration this is the config-table but not in the second iteration because the last load were your oracle-query.

Therefore take another look on the table-name if you fetched the right one and spelled it properly. You may it also including within your trace-logic, with something like:

let vTable = tablename(nooftables());
trace LastLoadedTable is: $(vTable);

Pico
Partner - Creator
Partner - Creator
Author

Love what are you doing here, it would have taken me ages to come up to this 🙂 Thank you very much!

The problem was indeed a typo in the code (a space to be precise: ' TabConfig' instead of 'TabConfig', ffs)

Again thank you, 

Best regards

P