>안녕 하세요 마늘맛 쿨피스 입니다 . 요금 e-abap.net에서 많은 정보, 문제 해결을 받고 있어서 모든 분께 감사 드림니다.
>필드 심볼을 써서 엄청 긴 소스를 줄일려고 하는데 자꾸 에러가 나서 그런데 좋은 해결 방법이 없을까요 ??
>그래서 질문 드립니다. 이거 해결되면 1000라인 이상 줄일수 있을거 같아서 질문 드립니다.
>
>Field symbol has not yet been assigned. 이런 에러가 나오네요 ㅠㅜ
>
>
>다시 수정 햇는데 안돌아 가네요 .
> >
>FORM INPUT USING p_seq.
gt_seq-seq = p_seq.
ENDFORM.
> >
>FORM AUTO.
FIELD-SYMBOLS :
FIELD-SYMBOLS :
FIELD-SYMBOLS :
DEFINE DIVIDE_MAC.
if &1 = 0. &3 = 0.
else.
&3 = ( &2 / &1 - 1 ) * 100.
endif.
end-of-definition.
DATA : A_CAL(3),
* B_CAL(3),
* C_CAL(3),
D_CAL(30),
E_CAL(30),
F_CAL(30).
DATA : Z_DATE LIKE P_DATE." LIKE P_DATE.
Z_DATE = P_DATE+4(2).
DO 24 TIMES.
PERFORM INPUT USING : '10', '11', '12', '13', '20', '21', '22','30',
'31', '32', '33', '34', '35', '36', '37', '38',
'40', '41', '42', '43' ,'44','50', '51', '52' .
A_CAL = A_CAL + 1.
CONCATENATE `gs_amt_profit-amt_` A_CAL INTO D_CAL.
CONCATENATE `gs_amt_fix12-amt_` Z_DATE INTO E_CAL.
CONCATENATE `gs_amt_fix-amt_` gt_seq-seq INTO F_CAL.
ASSIGN (A_CAL) TO
ASSIGN (E_CAL) TO
ASSIGN (F_CAL) TO
IF SY-SUBRC = 0.
"DIVIDE_MAC :
ELSE.
CLEAR :
ENDIF.
ENDDO.
"ENDCATCH.
ENDFORM.
>
>***********************************************************************************************8
>--수정전"""
> >
>FORM AUTO.
FIELD-SYMBOLS :
DATA : A_CAL(100),
B_CAL(100),
C_CAL(100),
D_CAL(100),
E_CAL(1000).
DATA : Z_DATE(100)." LIKE P_DATE.
Z_DATE = P_DATE+4(2).
CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 4 OTHERS = 8.
DO 24 TIMES.
"FREE
PERFORM INPUT USING : '10', '11', '12', '13', '20', '21', '22','30',
'31', '32', '33', '34', '35', '36', '37', '38','40', '41', '42', '43'
,'44','50', '51', '52' .
CONCATENATE 'gs_amt_fix' P_DATE+4(2) `-amt_` gt_seq-seq
` / gs_amt_fix-amt_` gt_seq-seq `- 1 ) * 100 .` INTO D_CAL.
* CONCATENATE : 'gs_amt_fix' Z_DATE INTO A_CAL.
* CONCATENATE : A_CAL `-amt_` INTO B_CAL.
* CONCATENATE : B_CAL ` / gs_amt_fix-amt_` INTO C_CAL.
* CONCATENATE : C_CAL gt_seq-seq INTO D_CAL.
* CONCATENATE : E_CAL `- 1 ) * 100 .` INTO E_CAL.
IF sy-subrc = 0.
ASSIGN (D_CAL) TO
gs_amt_profit-amt_1 =
"FREE
gs_amt_profit-amt_2 =
gs_amt_profit-amt_3 =
gs_amt_profit-amt_4 =
gs_amt_profit-amt_5 =
gs_amt_profit-amt_6 =
gs_amt_profit-amt_7 =
gs_amt_profit-amt_8 =
gs_amt_profit-amt_9 =
gs_amt_profit-amt_10 =
gs_amt_profit-amt_11 =
gs_amt_profit-amt_12 =
gs_amt_profit-amt_13 =
gs_amt_profit-amt_14 =
gs_amt_profit-amt_15 =
gs_amt_profit-amt_16 =
gs_amt_profit-amt_17 =
gs_amt_profit-amt_18 =
gs_amt_profit-amt_19 =
gs_amt_profit-amt_20 =
gs_amt_profit-amt_21 =
gs_amt_profit-amt_22 =
gs_amt_profit-amt_23 =
gs_amt_profit-amt_24 =
ELSE.
FREE
PERFORM AUTO.
ENDIF.
ENDDO.
ENDCATCH.
perform input 의 매개변수가 필드라는 가정하에 서로다른 3개에
같은 필드이름으로 계산이 될 거라는 자의적 해석에 의하여 필드는 24개까지만
설정하고 만들어봤습니다.
도움이 되시길 바랍니다.
DATA : BEGIN OF GS_AMT,
AMT_1 TYPE P DECIMALS 2 VALUE 100,
AMT_2 TYPE P DECIMALS 2 VALUE 100,
AMT_3 TYPE P DECIMALS 2 VALUE 100,
AMT_4 TYPE P DECIMALS 2 VALUE 100,
AMT_5 TYPE P DECIMALS 2 VALUE 100,
AMT_6 TYPE P DECIMALS 2 VALUE 100,
AMT_7 TYPE P DECIMALS 2 VALUE 100,
AMT_8 TYPE P DECIMALS 2 VALUE 100,
AMT_9 TYPE P DECIMALS 2 VALUE 100,
AMT_10 TYPE P DECIMALS 2 VALUE 100,
AMT_11 TYPE P DECIMALS 2 VALUE 100,
AMT_12 TYPE P DECIMALS 2 VALUE 100,
AMT_13 TYPE P DECIMALS 2 VALUE 100,
AMT_14 TYPE P DECIMALS 2 VALUE 100,
AMT_15 TYPE P DECIMALS 2 VALUE 100,
AMT_16 TYPE P DECIMALS 2 VALUE 100,
AMT_17 TYPE P DECIMALS 2 VALUE 100,
AMT_18 TYPE P DECIMALS 2 VALUE 100,
AMT_19 TYPE P DECIMALS 2 VALUE 100,
AMT_20 TYPE P DECIMALS 2 VALUE 100,
AMT_21 TYPE P DECIMALS 2 VALUE 100,
AMT_22 TYPE P DECIMALS 2 VALUE 100,
AMT_23 TYPE P DECIMALS 2 VALUE 100,
AMT_24 TYPE P DECIMALS 2 VALUE 100,
END OF GS_AMT,
GS_AMT_PROFIT LIKE GS_AMT,
GS_AMT_FIX12 LIKE GS_AMT,
GS_AMT_FIX LIKE GS_AMT.
DATA : BEGIN OF GT_SEQ,
SEQ TYPE C LENGTH 5,
END OF GT_SEQ.
DATA : A_CAL TYPE I,
A_CAL_C TYPE C LENGTH 3,
FNAME TYPE FNAME.
* make data ( temp ) - gs_amt_fix 생성.
DATA L_SEQ TYPE N LENGTH 2.
FIELD-SYMBOLS <FS_TEMP> TYPE ANY.
MOVE-CORRESPONDING GS_AMT TO : GS_AMT_FIX, GS_AMT_FIX12.
DO 24 TIMES.
ADD 1 TO L_SEQ.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE GS_AMT_FIX TO <FS_TEMP>.
IF SY-SUBRC IS INITIAL.
ADD L_SEQ TO <FS_TEMP>.
ENDIF.
ENDDO.
PERFORM INPUT USING : '10', '11', '12', '13', '20', '21', '22'.
*&---------------------------------------------------------------------*
*& Form INPUT
*&---------------------------------------------------------------------*
FORM INPUT USING P_SEQ. " 필드 위치라고 가정
DATA L_FNAME TYPE LVC_FNAME.
DATA L_DATE TYPE D.
FIELD-SYMBOLS : <LFS_PROFIT> TYPE ANY, " 이익~
<LFS_MM_AMT> TYPE ANY, " 월별
<LFS_AMOUNT> TYPE ANY. " 총
* seq 번호에 해당하는 필드를 기준으로 아래 계산식으로 계산한다고 가정
L_DATE = '20091201'. " 설정된 구조가 12월밖에 없음(임시)
UNASSIGN : <LFS_PROFIT>, <LFS_MM_AMT>, <LFS_AMOUNT>.
" Assign(GS_AMT_PROFIT) => Profit field
CONCATENATE `AMT_` P_SEQ INTO L_FNAME.
ASSIGN COMPONENT L_FNAME
OF STRUCTURE GS_AMT_PROFIT
TO <LFS_PROFIT>.
" Assign(GS_AMT_FIX) => amount field
ASSIGN COMPONENT L_FNAME
OF STRUCTURE GS_AMT_FIX
TO <LFS_AMOUNT>.
WRITE :/ L_FNAME.
" Assign(GS_AMT_FIXnn) => 월별 구조의 필드
CONCATENATE `GS_AMT_FIX` L_DATE+4(2) `-AMT_` P_SEQ INTO L_FNAME.
ASSIGN (L_FNAME) TO <LFS_MM_AMT>.
CATCH SYSTEM-EXCEPTIONS COMPUTE_INT_ZERODIVIDE = 1
BCD_OVERFLOW = 2
ARITHMETIC_ERRORS = 4
OTHERS = 8.
* 예) 식 : gs_amt_profit-amt_1 = ( gs_amt_fix12-amt_1 / gs_amt_fix-amt_1 ) * 100
<LFS_PROFIT> = ( <LFS_MM_AMT> / <LFS_AMOUNT> ) * 100.
ENDCATCH.
IF SY-SUBRC IS NOT INITIAL.
CASE SY-SUBRC.
WHEN 1. MESSAGE E208(00) WITH 'Divide 0 ... !!'.
WHEN 2. MESSAGE E208(00) WITH 'Overflow ... !!'.
WHEN 4. MESSAGE E208(00) WITH 'Arithmetic error'.
WHEN 8. MESSAGE E208(00) WITH 'Error( etc... !!)'.
ENDCASE.
ENDIF.
WRITE : 'Result :', <LFS_PROFIT>, '=',
'(', <LFS_MM_AMT>, '/', <LFS_AMOUNT>, ') * 100'.
ENDFORM. "INPUT
요요 님 감사 합니다 님 덕분에 많이 배우고 문제 해결 했습니다. 감사 합니다.