cancel
Showing results for 
Search instead for 
Did you mean: 

How to write Macro to check Characteristic Values

Former Member
0 Kudos

Dear SAP Experts,

I have a scenario as following:

- In DP, I create one my own Planning Object Structure “ZPOSDP03” with some Characteristics:

+ 9ALOCNO

+ 9AMATNR

+ Z_VALTYPE (this is my own Characteristic), including values like: ‘1’, ‘2’…

- With Tcode SPRO -> SCM Basis ->Master Data ->Maintain Free-Definable Attributes: I activate Field “ATT01” of Table “/SAPAPO/MATKEY”

- For Each Product-Location, I maintain a different value for Field “ATT01” by Tcode /SAPAPO/MAT1, tab Properties -> Additional Data, Field “ATT01”.

- In planning book PLB01, and Dataview DV01, I have two Key Figures:

            + ZQUANTITY

            +ZVALUE

- I need to write a macro to convert from ZQUANTITY to ZVALUE with conditions as followings:

            + If Char Z_VALTYPE = ‘1’:

                  Then ZVALUE = ZQUANTITY * MAT( 'ATT01' ; ACT_PRODUCT ; ACT_LOCATION )

            + If Char Z_VALTYPE = ‘2’:

                  Then ZVALUE = ZQUANTITY

Please Experts help me to write Macro for my scenario.

Thanks very much for your support!

Duyennx

Accepted Solutions (1)

Accepted Solutions (1)

former_member209769
Active Contributor
0 Kudos

hi Duyennx,

Why don't you keep it simple?

Have one selection having selection criteria as Z_VALTYPE = 1, and another selection having Z_VALTYPE = 2.

Do the simple calculation  ZVALUE = ZQUANTITY * MAT( 'ATT01' ; ACT_PRODUCT ; ACT_LOCATION )  for  Z_VALTYPE = 1 in one job for selection 1.

Have another job which would do the calculation ZVALUE = ZQUANTITY for selection 2.

PS: You could check for the value of characteristic Z_VALTYPE as being '1' and '2' using the statement(s)

IOBJNM_VALUE( 'Z_VALTYPE' ; '1' ) = 1   and

IOBJNM_VALUE( 'IOBJNM1' ; '2' ) = 1

respectively in a macro step. But unless you have an issue with my first recommendation, please try to do it by separating the selections. That should be the better way for macro execution.

Thanks - Pawan

Answers (1)

Answers (1)

rajkj
Active Contributor
0 Kudos

Hi Duyennx,

Here is a pseudo macro code to meet your requirement.

Step 1: 1 iteration

Macro Element: Action box (Read value)

                        LAYOUTVARIABLE_SET( 'VALTYPE' ; ACT_IOBJNM_VALUE( 'Z_VALTYPE' ) )

                       

Step 2: 1.. n iterations

IF [LAYOUTVAR_VALUE('VALTYPE') = 1 ]

ZVALUE = ZQUANTITY * MAT( 'ATT01' ; ACT_PRODUCT ; ACT_VERSION )

ELSEIF [LAYOUTVAR_VALUE('VALTYPE') = 2 ]  ( or just ELSE)

ZVLUE - ZQUANTITY

ENDIF

Thanks,

Rajesh