Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SUBROUTINE

Former Member
0 Kudos

Hi,

I had written subroutine form Validate_kunnr. But i made mistakes. plz corrrect me.

This is my program.

REPORT ZAC_TAB20.

  • T Y P E S

TYPES:

BEGIN OF TYVBAK,

VBELN TYPE VBAK-VBELN,

AUART TYPE VBAK-AUART,

AUDAT TYPE VBAK-AUDAT,

KUNNR TYPE VBAK-KUNNR,

NETWR TYPE VBAK-NETWR,

END OF TYVBAK.

  • D A T A D E C L A R A T I O N S

DATA:

STVBAK TYPE TYVBAK,

ITVBAK TYPE TABLE OF TYVBAK.

  • S E L E C T I O N S C R E E N

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:

SKUNNR FOR STVBAK-KUNNR.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

SELECT-OPTIONS:

SVBELN FOR STVBAK-VBELN MODIF ID M1,

SAUDAT FOR STVBAK-AUDAT MODIF ID M1.

SELECTION-SCREEN END OF BLOCK B2.

    • I N I T I A L I Z A T I O N

*INITIALIZATION.

*

    • FILLING SELECT OPTIONS WITH DEFAULTS

*

  • SKUNNR-SIGN = 'I'.

  • SKUNNR-OPTION = 'BT'.

  • SKUNNR-LOW = '1'.

  • SKUNNR-HIGH = '4000000'.

  • APPEND SKUNNR.

  • T O P O F P A G E

TOP-OF-PAGE.

WRITE:/1'SALES DOC',12 'DOC TYPE',20 'SALES DATE',32 'NETWORTH',60 'CUSTOMER'.

*A T S E L E C T I O N S C R E E N O U T P U T .

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'M1'.

SCREEN-ACTIVE = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

*IF SCREEN-NAME = 'SVBELN-HIGH'.

*

*

*SCREEN-INPUT = 0.

*MODIFY SCREEN.

*ENDIF.

*ENDLOOP.

  • A T S E L E C T I O N S C R E E N

AT SELECTION-SCREEN.

PERFORM VALIDATE_KUNNR.

<b>FORM VALIDATE_KUNNR.

DATA:

LW_KUNNR TYPE KNA1-KUNNR.

IF SKUNNR IS NOT INITIAL.

SELECT SINGLE KUNNR ON KNA1 INTO LW_KUNNR

WHERE KUNNR IN SKUNNR.

IF SY-SUBRC NE 0.

MESSAGE E000(0) WITH 'INVALID CUSTOMER'.

ELSE W_INPUT = 'X'.

ENDIF.

ELSE.

MESSAGE E000(0) WITH 'ENTER CUSTOMER NUMBER'.

ENDIF.

ENDFORM.</b>

Error is at the bold letters.

Also plz tell me why we r giving skunnr is not initial and

w_input = 'x'.

Plz let me know about usage of these two keys.

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

write as below

FORM VALIDATE_KUNNR.

DATA:LW_KUNNR TYPE KNA1-KUNNR.

<b>IF NOT SKUNNR[] IS INITIAL.</b>

SELECT SINGLE KUNNR <b>FROM</b> KNA1 INTO LW_KUNNR

WHERE KUNNR IN SKUNNR.

IF SY-SUBRC NE 0.

MESSAGE E000(0) WITH 'INVALID CUSTOMER'.

ELSE W_INPUT = 'X'.

ENDIF.

ELSE.

MESSAGE E000(0) WITH 'ENTER CUSTOMER NUMBER'.

ENDIF.

ENDFORM.

<b>Reward points for useful Answers</b>

Regards

Anji

9 REPLIES 9

Former Member
0 Kudos

hi,

SELECT SINGLE KUNNR FROM KNA1 INTO LW_KUNNR

WHERE KUNNR IN SKUNNR.

Is not initial means there are some records for the condition u have given and

= 'X' means u r entering some value for that field.

Message was edited by:

Roja Velagapudi

Former Member
0 Kudos

Hi

write as below

FORM VALIDATE_KUNNR.

DATA:LW_KUNNR TYPE KNA1-KUNNR.

<b>IF NOT SKUNNR[] IS INITIAL.</b>

SELECT SINGLE KUNNR <b>FROM</b> KNA1 INTO LW_KUNNR

WHERE KUNNR IN SKUNNR.

IF SY-SUBRC NE 0.

MESSAGE E000(0) WITH 'INVALID CUSTOMER'.

ELSE W_INPUT = 'X'.

ENDIF.

ELSE.

MESSAGE E000(0) WITH 'ENTER CUSTOMER NUMBER'.

ENDIF.

ENDFORM.

<b>Reward points for useful Answers</b>

Regards

Anji

0 Kudos

hI,

iAM GETTING fIELD W_INPUT IS UNKNOWN.

0 Kudos

check if W_INPUT is being used anywhere else in the program

if it is then declare it as

data: W_INPUT.

if it is not being used then simply delete the 'else w_input = 'X'.' line

Former Member
0 Kudos

Hi Rams,

I think you should use "IF SKUNNR[] IS NOT INITIAL" instead of "IF SKUNNR IS NOT INITIAL".

I hope it helps. Best regards,

Alvaro

Former Member
0 Kudos

Hi,

FORM VALIDATE_KUNNR.

DATA:

LW_KUNNR TYPE KNA1-KUNNR.

IF SKUNNR IS NOT INITIAL.

SELECT SINGLE KUNNR ON KNA1 INTO LW_KUNNR

WHERE KUNNR IN SKUNNR.

IF SY-SUBRC NE 0.

MESSAGE E000(0) WITH 'INVALID CUSTOMER'.

ELSE W_INPUT = 'X'.

ENDIF.

ELSE.

MESSAGE E000(0) WITH 'ENTER CUSTOMER NUMBER'.

ENDIF.

ENDFORM.

In the form the the error might be because you are using a SELECT OPTIONS parameter in the where condition but the select options allows you to enter a range of values.In that case the select single statement may not work as one place you want to select single and at the other you are using a select options.

Also the initial check is useful as it prevents unnecessary database access.

The select-options is just like an internal table.If it is empty and you do a select then unnecessary database access will take place which will reduce performance.

So an initial check is done.

Hope it will be useful.

Thanks,

Sandeep.

former_member189059
Active Contributor
0 Kudos

checking skunnr will refer to a structure (or header line or work area) with that name

to refer to a table of the name skunnr use skunnr[]

gopi_narendra
Active Contributor
0 Kudos

You are trying to get a single value from KNA1 by validating against a select-options.

Select-Options is nothing but an internal table. So you cant do it that way.

And first of all change your declaration of selection screen.

* S E L E C T I O N S C R E E N
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: SKUNNR FOR VBAK-KUNNR.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS: SVBELN FOR VBAK-VBELN MODIF ID M1,
                              SAUDAT FOR VBAK-AUDAT MODIF ID M1.
SELECTION-SCREEN END OF BLOCK B2.

STVBAK is an internal table and you are using it in the declaration, which cant be used.

Regards

Gopi.

Former Member
0 Kudos

Hi please use..

IF SKUNNR IS NOT INITIAL.

SELECT SINGLE KUNNR <b>FROM</b> KNA1 INTO LW_KUNNR.

Reward if helpful..

Regards

Prax