<jsp:directive.page pageEncoding="UTF-8" />
<og:query command="{@command}" debug="{@debug}" maxRowCount="0">
	select '1' as WRITABLE,UPPER(TABLE_NAME) AS TABLE_NAME,UPPER(CLM) AS CLM,NAME_JA,
			RENDERER,EDITOR,DBTYPE,0 SEQ,'' CODE,'' CODENAME,
			trim(REGEXP_SUBSTR(BIKO,'([^ ]+:[^ ]+[ ]*)+' )) as BIKO,UNIQ,SYSTEM_ID
	from GF05
	where SYSTEM_ID = '{@SYSTEM_ID_D}'
	and   TBLSYU    = '{@TBLSYU_D}'
	<og:where startKey="and">
		<og:and value="TABLE_NAME like '{@TABLE_NAME_D}'"	/>
		<og:and value="CLM        like '{@CLM_D}'"			/>
	</og:where>
	and   KBCLM		<= '7'
	and   FGJ       = '1'
	and   ( EDITOR = 'MENU' OR RENDERER = 'MENU' )
	order by CLM,TABLE_NAME
</og:query>

<og:query command="{@command}" debug="{@debug}" dbid="{@DBID_R}" maxRowCount="0" scope="request">
	select '0' as WRITABLE,'' as TABLE_NAME,CLM,NAME_JA,
			RENDERER,EDITOR,DBTYPE,0 SEQ,'' as CODE,'' as CODENAME,'' as BIKO,UNIQ,SYSTEM_ID
	from GEA03
	where SYSTEM_ID in ( '{@SYSTEM_ID_R}','{@AST}' )
	<og:where startKey="and">
		<og:and value="CLM like '{@CLM_R}'" />
	</og:where>
	and   FGJ       = '1'
	and   ( EDITOR = 'MENU' OR RENDERER = 'MENU' )
	ORDER BY SYSTEM_ID DESC, KBSAKU DESC, CLM
</og:query>

<og:tableFilter
	classId	= "DBSELECT"
	dbid	= "{@DBID2}"
	scope	= "request"
	keys	= "APPEND"
	vals	= "true"
	selectedAll	= "true"
>
	select CASE
			WHEN B.LNAME LIKE '%:%' THEN B.LNAME
			ELSE A.CODE||':'||B.LNAME END BIKO
	from GEA04 A inner join GEA08 B
	on A.CLM||'.'||A.CODE = B.CLM
	and A.FGJ = B.FGJ
	and A.SYSTEM_ID = B.SYSTEM_ID
	where A.SYSTEM_ID = [SYSTEM_ID]
	and A.CLM = [CLM]
	and A.FGJ = '1'
	and B.LANG = 'ja'
	order by A.CLM,A.SEQNO
</og:tableFilter>

<og:tableMerge
	action        = "DIFFERENCE"
	masterScope   = "session"
	masterKeys    = "CLM"
	diffKeys      = "BIKO"
	modifyClms    = "UNIQ"
	slaveScope    = "request"
	display       = "true"
/>

<og:tableFilter classId="BIKO2CODE" />

<og:value key="lblKey" value="C" />

<og:hidden name="SQL">
	INSERT INTO GEA04
		(SYSTEM_ID,CLM,CODE,SEQNO,CODELVL,KBSAKU,
		 FGJ,DYSET,DYUPD,USRSET,USRUPD,PGUPD)
	VALUES
		('{@SYSTEM_ID_R}',[CLM],[CODE],[SEQ],1,'1',
		 '1','{@USER.YMDH}','{@USER.YMDH}','{@USER.ID}','{@USER.ID}','{@GUI.KEY}')
</og:hidden>

<og:hidden name="SQL2">
	INSERT INTO GEA08
		(SYSTEM_ID,CLM,
		 NAME_JA,LNAME,
		 KBSAKU,KBLBL,LANG,FGJ,DYSET,DYUPD,USRSET,USRUPD,PGUPD)
	VALUES
		('{@SYSTEM_ID_R}',[CLM]||'.'||[CODE],
		 [CODENAME],[CODENAME],
		 '1','6','ja','1','{@USER.YMDH}','{@USER.YMDH}','{@USER.ID}','{@USER.ID}','{@GUI.KEY}')
</og:hidden>

<!-- コードリソース(GEA04) をINSERT するので、既存のリソースを、削除(FGJ='9')する。 -->
<og:hidden name="SQLD">
	UPDATE GEA04 SET
			FGJ		= '9',
			DYUPD	= '{@USER.YMDH}',
			USRUPD	= '{@USER.ID}',
			PGUPD	= '{@GUI.KEY}'
	WHERE	SYSTEM_ID	= '{@SYSTEM_ID_R}'
	AND		CLM			= [CLM]
	AND		KBSAKU		!= '0'
</og:hidden>

<!-- コードリソース(GEA04) をINSERT するので、既存のリソースを、削除(FGJ='9')する。 -->
<og:hidden name="SQLD2">
	UPDATE GEA08 SET
			FGJ		= '9',
			DYUPD	= '{@USER.YMDH}',
			USRUPD	= '{@USER.ID}',
			PGUPD	= '{@GUI.KEY}'
	WHERE	SYSTEM_ID	= '{@SYSTEM_ID_R}'
	AND		CLM			like [CLM]||'.%'
	AND		KBSAKU		!= '0'
</og:hidden>

<og:hidden name="DBID2" value="{@DBID_R}" />
