on 10-14-2020 10:44 AM
Hi Gurus,
I' new to AMDP still exploring the area. I have a simple requirement that i can achieve through Formula in BW4HANA Transformation. But to explore i chose to create a AMDP in End routine.
My requirement is to check the length of a field, and then assign first two letters to another field in ADSO, then check length assign first 4 letters to another and so on. I have tried to write the Code, But i'm getting an syntax error which i don't understand at all. Requesting you to please help me on this. Below is the code in AMDP Method.
IT_TAB = SELECT "/BIC/ZPRD_HIER",
case
when length ( inTab."/BIC/ZPRD_HIER" ) >= 8 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,8 ) as /BIC/ZSG_BCAT1,
when length ( inTab."/BIC/ZPRD_HIER" ) >= 10 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,10 ) as /BIC/ZSG_BCAT2,
when length ( inTab."/BIC/ZPRD_HIER" ) >= 2 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,2 ) as /BIC/ZSG_BRAND,
when length ( inTab."/BIC/ZPRD_HIER" ) >= 4 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,4 ) as /BIC/ZSG_LINE,
when length ( inTab."/BIC/ZPRD_HIER" ) >= 6 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,6 ) as /BIC/ZSG_SLINE,
RECORD,
SQL__PROCEDURE__SOURCE__RECORD FROM :inTab;
Attached is the screen shot with syntax Error.
Hi,
you can not use one CASE statement for several columns. You need one CASe per column.
And the CASE syntax starts with CASE and ends with END.
Torsten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry I'm to fast.
I'd thought there are couple of rows but it's only one 😉
The Syntax for case is:
CASE <expression>
WHEN <expression> THEN <expression>
[{ WHEN <expression> THEN <expression>}…]
[ ELSE <expression>]
END
That means for your routine coding:
tempTAB = SELECT "/BIC/ZPRD_HIER",
case when length ( inTab."/BIC/ZPRD_HIER" ) >= 8 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,8 ) END as /BIC/ZSG_BCAT1,
CASE when length ( inTab."/BIC/ZPRD_HIER" ) >= 10 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,10 ) END as /BIC/ZSG_BCAT2,
CASE when length ( inTab."/BIC/ZPRD_HIER" ) >= 2 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,2 ) END as /BIC/ZSG_BRAND,
CASE when length ( inTab."/BIC/ZPRD_HIER" ) >= 4 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,4 ) END as /BIC/ZSG_LINE,
CASE when length ( inTab."/BIC/ZPRD_HIER" ) >= 6 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,6 ) END as /BIC/ZSG_SLINE,
RECORD,
SQL__PROCEDURE__SOURCE__RECORD FROM :inTab;
Torsten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Torsten,
That worked like magic. Thank you so much. But i'm wondering why we need to include End? because my statement is not ending with one "when" i have many to go, As per the syntax of Case "end" should be placed at the actual end. Am i missing anything?Please enlighten me
Regards,
Ram
CASE<expression>
WHEN<expression>THEN<expression>
[{WHEN<expression>THEN<expression>}…]
[ELSE<expression>]
END
Hi,
1. you must surround the column name by double quotes like
when length ( inTab."/BIC/ZPRD_HIER" ) >= 8 THEN SUBSTRING( inTab."/BIC/ZPRD_HIER",1,8 ) as "/BIC/ZSG_BCAT1",
2. writing the result back into th inTab is not a good idea in case you need intermediate results use a new name like tempTab or similar
Torsten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.